<template>
  <div class="ai-naming-page">
    <div class="page-header">
      <h1>✨ AI智能起名</h1>
      <p>融合生辰八字与AI智慧的传统起名艺术</p>
    </div>

    <div class="page-content">
      <!-- 哲学理念 -->
      <div class="philosophy-section">
        <strong>起名理念：</strong>结合《易经》八卦理论、五行相生相克原理，运用现代人工智能技术，
        为您宝宝提供既符合传统美学又具有现代气息的名字选择。
      </div>

      <!-- 起名表单 -->
      <div class="naming-form">
        <h3>📝 基本信息</h3>

        <div class="form-row">
          <label>
            <span>宝宝生辰</span>
            <input type="datetime-local" v-model="birthDate" required>
          </label>
          <label>
            <span>父亲姓氏</span>
            <input type="text" v-model="fatherName" placeholder="请输入父亲姓氏" required>
          </label>
        </div>

        <div class="form-row">
          <label>
            <span>母亲姓氏</span>
            <input type="text" v-model="motherName" placeholder="请输入母亲姓氏">
          </label>
          <label>
            <span>宝宝性别</span>
            <select v-model="babyGender">
              <option value="undefined">不限</option>
              <option value="boy">男</option>
              <option value="girl">女</option>
            </select>
          </label>
        </div>

        <div class="form-row">
          <label>
            <span>风格偏好</span>
            <select v-model="preferredStyle">
              <option value="classical">古典雅致</option>
              <option value="modern">现代简约</option>
              <option value="poetic">诗意唯美</option>
              <option value="strength">大气磅礴</option>
            </select>
          </label>
          <label>
            <span>关键词</span>
            <input type="text" v-model="keywords" placeholder="希望包含的字词（可选）">
          </label>
        </div>

        <button class="generate-btn" @click="generateNames" :disabled="isGenerating">
          <span v-if="!isGenerating">✨ 生成名字</span>
          <span v-else>⏳ 生成中...</span>
        </button>
      </div>

      <!-- 起名结果 -->
      <div class="naming-results">
        <h3>🎨 推荐名字</h3>

        <div class="results-grid">
          <div
            v-for="name in generatedNames"
            :key="name.id"
            class="name-card"
            :class="{ favorite: name.isFavorite }"
          >
            <div class="name-main">{{ name.fullName }}</div>
            <div class="name-meaning">{{ name.meaning }}</div>
            <div class="name-wuxing">{{ name.wuxing }}属性</div>

            <div class="name-actions">
              <button
                class="favorite-btn"
                @click="toggleFavorite(name)"
                :class="{ active: name.isFavorite }"
              >
                {{ name.isFavorite ? '❤️' : '🤍' }}
              </button>
              <button class="copy-btn" @click="copyToClipboard(name.fullName)">📄</button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

// 表单数据
const birthDate = ref('')
const fatherName = ref('')
const motherName = ref('')
const babyGender = ref('undefined')
const preferredStyle = ref('classical')
const keywords = ref('')

// 状态
const isGenerating = ref(false)
const generatedNames = ref([])

// 名字数据库
const nameData = {
  classical: ['子轩', '子涵', '诗涵', '俊熙', '思源'],
  modern: ['星辰', '晨曦', '云端', '光影'],
  poetic: ['清扬', '婉约', '流萤', '听雨'],
  strength: ['天行', '浩然', '擎天', '烽火']
}

const meanings = {
  '子轩': '才俊之子，气宇轩昂',
  '子涵': '才情文雅，包容万物',
  '星辰': '如星辰般闪耀璀璨',
  '晨曦': '清晨的阳光，充满希望',
  '清扬': '清新悠扬，心境开阔',
  '天行': '天道运行，自强不息'
}

const wuxingData = {
  '子轩': '金',
  '子涵': '木',
  '星辰': '火',
  '晨曦': '火',
  '清扬': '水',
  '天行': '土'
}

// 生成名字
function generateNames() {
  if (!birthDate.value || !fatherName.value) {
    alert('请填写宝宝生辰和父亲姓氏！')
    return
  }

  isGenerating.value = true

  // 模拟AI分析过程
  setTimeout(() => {
    const selectedNames = nameData[preferredStyle.value].slice(0, 4)
    generatedNames.value = selectedNames.map((name, index) => ({
      id: Date.now() + index,
      fullName: fatherName.value + name,
      meaning: meanings[name] || '寓意美好，吉祥如意',
      wuxing: wuxingData[name] || '未知',
      isFavorite: false
    }))

    isGenerating.value = false
  }, 2000)
}

// 切换收藏
function toggleFavorite(name) {
  name.isFavorite = !name.isFavorite
}

// 复制到剪贴板
function copyToClipboard(text) {
  navigator.clipboard.writeText(text).then(() => {
    alert(`已复制: ${text}`)
  })
}
</script>

<style scoped>
.ai-naming-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 2rem 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.page-header {
  text-align: center;
  margin-bottom: 3rem;
  padding: 0 2rem;
}

.page-header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.page-header p {
  font-size: 1.1rem;
  color: #666;
}

.page-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

.philosophy-section {
  background: rgba(255, 255, 255, 0.9);
  padding: 1.5rem;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  margin-bottom: 3rem;
  text-align: center;
  backdrop-filter: blur(10px);
}

.naming-form {
  background: rgba(255, 255, 255, 0.9);
  padding: 2rem;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  margin-bottom: 3rem;
  backdrop-filter: blur(10px);
}

.naming-form h3 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 2rem;
  text-align: center;
  color: #333;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.form-row label {
  display: flex;
  flex-direction: column;
}

.form-row label span {
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: #555;
}

.form-row input,
.form-row select {
  padding: 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s;
}

.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: #6a11cb;
}

.generate-btn {
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  margin-top: 1rem;
}

.generate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(106, 17, 203, 0.3);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.naming-results {
  background: rgba(255, 255, 255, 0.9);
  padding: 2rem;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  backdrop-filter: blur(10px);
}

.naming-results h3 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 2rem;
  text-align: center;
  color: #333;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.name-card {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.5rem;
  transition: all 0.3s ease;
  position: relative;
}

.name-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border-color: #6a11cb;
}

.name-card.favorite {
  background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
  border-color: #ffc107;
}

.name-main {
  font-size: 1.3rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 0.5rem;
  text-align: center;
}

.name-meaning {
  font-size: 0.9rem;
  color: #666;
  line-height: 1.5;
  margin-bottom: 0.5rem;
  text-align: center;
}

.name-wuxing {
  font-size: 0.8rem;
  color: #666;
  text-align: center;
  margin-bottom: 1rem;
  padding: 0.25rem 0.5rem;
  background: rgba(106, 17, 203, 0.1);
  border-radius: 4px;
  display: inline-block;
}

.name-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.favorite-btn,
.copy-btn {
  flex: 1;
  padding: 0.5rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.favorite-btn {
  background: #e9ecef;
  color: #666;
}

.favorite-btn:hover,
.name-card.favorite .favorite-btn {
  background: #ffc107;
  color: #333;
}

.copy-btn {
  background: #e9ecef;
  color: #666;
}

.copy-btn:hover {
  background: #6a11cb;
  color: white;
}

@media (max-width: 768px) {
  .page-header {
    padding: 0 1rem;
  }

  .page-content {
    padding: 0 1rem;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .results-grid {
    grid-template-columns: 1fr;
  }
}
</style>